import request from '@/axios'
import { buildFilter } from './types'

/** 处理查询的通用方法,只传需要筛选的参数 */
function getFilter(data = { pageNum: 1, pageSize: 10, total: 0 } as any) {
  var filter = {
    pageNum: data.pageNum,
    pageSize: data.pageSize,
    groups: [],
    rules: [],
    //orderBys: [{ fieldName: "createOn", order: "DESC" }],//默认根据createOn创建时间倒序排列
    orderBys: [] //默认根据createOn创建时间倒序排列
  } as buildFilter
  // if (data.simpleSearchText) {
  //     filter.groups.push({
  //         groupOp: 'OR',
  //         rules: [
  //             {
  //                 field: 'title',
  //                 data: data.simpleSearchText,
  //                 opType: 'Contains',
  //             },
  //             {
  //                 field: 'content',
  //                 data: data.simpleSearchText,
  //                 opType: 'Contains',
  //             },
  //         ],
  //     })
  // }
  let { pageNum, pageSize, total, orderBys, ...d } = data
  filter.orderBys = orderBys || []
  for (const key in d) {
    if (Object.prototype.hasOwnProperty.call(d, key)) {
      // if (d[key] !== '') {
      //   filter.rules.push({
      //     field: key,
      //     data: d[key],
      //     opType: 'Equals'
      //   })
      // }
      if (d[key] !== '' && d[key] !== undefined && d[key] !== null) {
        if (key.indexOf('$') > -1) {
          filter.rules.push({
            field: key.split('$')[0],
            data: d[key],
            opType: key.split('$')[1],
            dataType: 'STR'
          })
        } else {
          filter.rules.push({
            field: key,
            data: d[key],
            opType: d[key] instanceof Array ? 'In' : 'Equals',
            dataType: 'STR'
          })
        }
      }
    }
  }
  return filter
}

//科技成果---列表
export function cmsAchievement(data: any) {
  return request.post({
    url: `/wl/cmsWebAchievement/`,
    data: getFilter(data)
  })
}
//科技成果---详情
export function cmsAchievementDetail(data: any) {
  return request.post({
    url: `/wl/cmsWebAchievement/detail`,
    data: { data, rid: '0' }
  })
}
//会议培训---列表
export function cmsTraining(data: any) {
  return request.post({
    url: `/wl/cmsWebTraining/`,
    data: getFilter(data)
  })
}
//会议培训---详情
export function cmsTrainingDetail(data: any) {
  return request.post({
    url: `/wl/cmsWebTraining/detail`,
    data: { data, rid: '0' }
  })
}
//典型案例---列表
export function cmsClassicCase(data: any) {
  return request.post({
    url: `/wl/cmsWebClassicCase/`,
    data: getFilter(data)
  })
}
//典型案例---详情
export function cmsClassicCaseDetail(data: any) {
  return request.post({
    url: `/wl/cmsWebClassicCase/detail`,

    data: { data, rid: '0' }
  })
}
//文章---列表
export function cmsArticle(data: any) {
  return request.post({
    url: `/wl/cmsWebArticle/`,
    data: getFilter(data)
  })
}
//文章---详情
export function cmsArticleDetail(data: any) {
  return request.post({
    url: `/wl/cmsWebArticle/detail`,

    data: { data, rid: '0' }
  })
}
//中心简介---列表
export function cmsCentreBlurb(data: any) {
  return request.post({
    url: `/wl/cmsWebCentreBlurb/`,
    data: getFilter(data)
  })
}
//中心简介修改---详情
export function cmsCentreBlurbDetailsDetail(data: any) {
  return request.post({
    url: `/wl/cmsWebCentreBlurbDetails/detail`,

    data: { data, rid: '0' }
  })
}

export function fetchDictionaryData() {
  return request.post({
    url: `/wl/cmsWebDictionary/getDictAll`
  })
}

//#region 需求发布接口

// 需求发布---列表
export function cmsRequirementRelease(data: any) {
  return request.post({
    url: `/wl/cmsRequirementRelease/`,
    data: getFilter(data)
  })
}

// 需求发布---新增
export function cmsRequirementReleaseCreate(data: any) {
  return request.post({
    url: `/web/cmsRequirementRelease/create`,
    data: data
  })
}

// 需求发布---详情
export function cmsRequirementReleaseDetail(data: any) {
  return request.post({
    url: `/wl/cmsRequirementRelease/detail`,
    data: { data, rid: '0' }
  })
}

// 需求发布---审核列表
export function cmsRequirementReleaseGetAuditorList(data: any) {
  return request.post({
    url: `/web/cmsRequirementRelease/getAuditorList`,
    data: data
  })
}
// 需求发布---我的需求列表
export function cmsRequirementReleaseGetMyList(data: any) {
  return request.post({
    url: `/web/cmsRequirementRelease/getMyList`,
    data: data
  })
}
// 需求发布---审核接口
export function cmsRequirementReleaseProcess(data: any) {
  return request.post({
    url: `/web/cmsRequirementRelease/process`,
    data: { data, rid: '0' }
  })
}

// 需求发布---更新
export function cmsRequirementReleaseSave(data: any) {
  return request.post({
    url: `/web/cmsRequirementRelease/save`,
    data: data
  })
}
//#endregion

//#region 需求解决方案接口

// 解决方案---列表
export function cmsRequirementSolution(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/`,
    data: getFilter(data)
  })
}

// 解决方案---新增
export function cmsRequirementSolutionCreate(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/create`,
    data: data
  })
}

// 解决方案---详情
export function cmsRequirementSolutionDetail(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/detail`,
    data: { data, rid: '0' }
  })
}
// 解决方案---我的方案
export function cmsRequirementSolutionGetMyList(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/getMyList`,
    data: { data, rid: '0' }
  })
}
// 解决方案---状态变更
export function cmsRequirementSolutionProcessUpdate(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/processUpdate`,
    data: { data, rid: '0' }
  })
}

// 解决方案---更新
export function cmsRequirementSolutionSave(data: any) {
  return request.post({
    url: `/web/cmsRequirementSolution/save`,
    data: data
  })
}
//#endregion
